package com.hue.nio.day02.two;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.SocketChannel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

/*
    群聊系统客户端：
        接收发送消息
 */
public class Client {
    public static SocketChannel socketChannel = null;

    public static ExecutorService threadPool = Executors.newFixedThreadPool(2);

    public Client() {
        try {
            socketChannel = SocketChannel.open(new InetSocketAddress("localhost", 7777));
            socketChannel.configureBlocking(false);
            //创建一个线程来处理客户端的读事件
            threadPool.submit(new ClientReadThread(socketChannel));
            //创建一个线程来处理客户端的写事件
            threadPool.submit(new ClientWriteThread(socketChannel));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new Client();
    }
}
